import { useSelector } from 'react-redux'

export default function withTranslate(Component) {
  return function WrappedComponent(props) {
    const { translations } = useSelector((state) => state.lang)
    const t = (key) => key.split('.').reduce((o, k) => (o || {})[k], translations)
    
    return <Component {...props} t={t} />
  }
}